package com.example.zrq1010110087.graceplayer.theme;

import android.content.Context;
import android.content.SharedPreferences;
import android.view.ViewGroup;

import com.example.zrq1010110087.graceplayer.R;

/**
 * Created by zrq1010110087 on 2017/10/26.
 */

public class ThemeUntils {

    private static String[] themes;//themes[0]为默认主题
    private ViewGroup viewGroup;
    private String theme;
    private SharedPreferences sharedPreferences;
     public ThemeUntils(Context context, ViewGroup viewGroup){

         this.viewGroup=viewGroup;
         this.themes=context.getResources().getStringArray(R.array.theme);
         this.sharedPreferences=context.getSharedPreferences("theme.cfg",Context.MODE_PRIVATE);
         this.theme=sharedPreferences.getString("theme",themes[0]);//themes[0]为默认主题

     }


    public void setTheme(int which) {
        //保存主题信息
        this.theme = themes[which];
        SharedPreferences.Editor editor=sharedPreferences.edit();
        editor.putString("theme",theme);
        editor.commit();
        //判断并设置背景
        switch (which){

             case   0:this.viewGroup.setBackgroundResource(R.mipmap.bg_blur); break;
             case   1:this.viewGroup.setBackgroundResource(R.mipmap.bg_snow); break;
             case   2: this.viewGroup.setBackgroundResource(R.mipmap.bg_color); break;
             case   3:  this.viewGroup.setBackgroundResource(R.mipmap.bg_digit_flower);break;
             case   4: this.viewGroup.setBackgroundResource(R.mipmap.bg_mountain);break;
             case   5:this.viewGroup.setBackgroundResource(R.mipmap.bg_running_dog); break;
             case   6:this.viewGroup.setBackgroundResource(R.mipmap.bg_music_girl); break;

        }

    }

    public String getTheme() {
        return theme;
    }
}
